((lambda ()
  (var throttle     null)
  (var last-query   "")
  (var empty-search (object "query" "" "results" (array)))
  (return (lambda search (id evt)
    (var q evt.target.value)
    (= q (q.trim))
    (if throttle (clear-timeout throttle))
    (if (!== q last-query) (block
      (= last-query q)
      (if (== q "")
        (./results id empty-search)
        (= throttle (set-timeout (.bind ./search null id q) 400)))))))))
